package com.chilli.cosima.action.usermanager;

import java.util.List;
import java.util.Map;

import com.chilli.cosima.action.BaseSupport;
import com.chilli.cosima.data.bean.TOperator;
import com.chilli.cosima.data.bean.TRole;
import com.chilli.cosima.service.UserService;

public class UserQueryAction extends BaseSupport
{
	/**
	 * 注释内容
	 */
	private static final long serialVersionUID = 4831037792694839497L;

	private UserService userService;

	private TOperator user;

	private Long id;

	private List<TRole> roles;

	public String detail()
	{

		TOperator user = (TOperator) userService.findUserById(id);

		if (null != user)
		{
			this.user = user;
			roles = userService.findAllRoles();
			return DETAIL;
		} else
		{
			logger.error("error");
			return ERROR;
		}

	}

	@SuppressWarnings("unchecked")
	public String execute()
	{

		String page = request.getParameter("page");
		int current = 0;
		if (page != null && !"".equals(page))
		{
			current = Integer.parseInt(page);
		}

		Map map = userService.findUserByPage(current, pageSize);
		List list = (List) map.get("list");
		int count = (Integer) map.get("count");

		setPager(list, "user/userQueryAction.action", count);

		return SUCCESS;
	}

	public UserService getUserService()
	{
		return userService;
	}

	public void setUserService(UserService userService)
	{
		this.userService = userService;
	}

	public TOperator getUser()
	{
		return user;
	}

	public void setUser(TOperator user)
	{
		this.user = user;
	}

	public Long getId()
	{
		return id;
	}

	public void setId(Long id)
	{
		this.id = id;
	}

	public List<TRole> getRoles()
	{
		return roles;
	}

	public void setRoles(List<TRole> roles)
	{
		this.roles = roles;
	}

}
